package com.sk.sqd.strategy;

import org.springframework.stereotype.Component;

import java.math.BigDecimal;

/**
 * 返利收费算法，初始化传入返利条件和返利值
 */
@Component
public class CashReturnStrategy extends CashStrategy {

    @Override
    public BigDecimal acceptCash(BigDecimal money, Double moneyRebate, Double moneyCondition, Double moneyReturn) {
        BigDecimal result = money;
        BigDecimal condition = BigDecimal.valueOf(moneyCondition == null ? 300.0d : moneyCondition);
        BigDecimal returnMoney = BigDecimal.valueOf(moneyReturn == null ? 100.0d : moneyReturn);
        // 如果大于返利条件，要减去返利值
        if (money.compareTo(condition) > -1) {
            result = money.subtract(money.divideAndRemainder(condition)[0].multiply(returnMoney));
        }
        return result.setScale(2);
    }

    @Override
    public String type() {
        return "return";
    }

}
